package com.djdg.foodies.admin.controller;

import com.djdg.foodies.admin.service.TestService;
import com.djdg.foodies.common.base.Result;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.djdg.foodies.common.base.Result.success;

/**
 * @Description:
 * @Auther Demon
 * @Date 2018/3/13 11:28 星期二
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Resource
    private TestService testService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("hello")
    public Result hello() {
        if(!stringRedisTemplate.hasKey("test")) {
            stringRedisTemplate.opsForValue().set("test", "hiiiiiii");
        }
        return success("成功", stringRedisTemplate.opsForValue().get("test"));
    }

    @GetMapping("user/{name}")
    public Result hello(@PathVariable("name") String name) {
        return success(testService.getTestUser(name));
    }

}
